import React from "react";
import { getFloorBySlug } from "../../../../lib/data";
import { ProductGrid } from "../../../../components/ProductGrid";

export const revalidate = 300;

export default function ChannelPage({ params }: { params: { locale: string; slug: string } }) {
  const floor = getFloorBySlug(params.slug, params.locale);
  if (!floor) {
    return (
      <div className="mx-auto max-w-screen-2xl px-4 py-12">
        <h1 className="text-2xl font-semibold">Channel Not Found</h1>
        <a className="mt-6 inline-block text-blue-600" href={`/${params.locale}`}>Back</a>
      </div>
    );
  }
  return (
    <div className="mx-auto max-w-screen-2xl px-4 py-8 space-y-8">
      <div className="flex items-center justify-between">
        <h1 className="text-2xl font-semibold">{floor.title}</h1>
        <a href={`/${params.locale}`} className="text-sm text-gray-600 hover:text-gray-900">{params.locale === 'en' ? 'Home' : '返回首页'}</a>
      </div>
      {floor.hero && (
        <a href={floor.hero.href ?? `/${params.locale}`} className="block rounded-xl overflow-hidden">
          <img src={floor.hero.image} alt={floor.hero.title ?? floor.title} className="w-full object-cover aspect-[16/6]" />
        </a>
      )}
      <ProductGrid items={floor.products} basePath={`/${params.locale}`} />
    </div>
  );
}


